local sk_le__feijiang = fk.CreateSkill {

  name = "sk_le__feijiang",

  tags = {},

}



sk_le__feijiang:addEffect("viewas", {
  name = "sk_le__feijiang",
  pattern = "slash",
  anim_type = "offensive",
  prompt = "#sk_le__feijiang",
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    local card = Fk:cloneCard("slash")
    card.skillName = sk_le__feijiang.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = player:getCardIds("h")
    local yes = table.find(cards, function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeWeapon
    end)
    player:throwAllCards("h")
    if not player.dead then
      player:drawCards(#cards, sk_le__feijiang.name)
    end
    use.extra_data = use.extra_data or {}
    use.extra_data.sk_le__feijiang = true
    if not player.dead then
      local choices = { "sk_le__feijiang2" }
      if table.find(use.tos, function(p)
            return not p:isNude()
          end) then
        table.insert(choices, 1, "sk_le__feijiang1")
      end
      local choice
      if not yes then
        choice = room:askForChoice(player, choices, sk_le__feijiang.name)
      end
      if yes or choice == "sk_le__feijiang1" then
        for _, p in ipairs(use.tos) do
          local to = p
          if not to.dead and not to:isNude() then
            to:addToPile(sk_le__feijiang.name, to:getCardIds("hej"), false, sk_le__feijiang.name)
          end
        end
      end
      if yes or choice == "sk_le__feijiang2" then
        for _, p in ipairs(use.tos) do
          local to = p
          room:addPlayerMark(to, MarkEnum.SkInvalidity .. "-turn", 1)
          room:addPlayerMark(to, "@@SkInvalidity-turn", 1)
        end
      end
      if yes then
        player:setSkillUseHistory(sk_le__feijiang.name, 0, Player.HistoryTurn)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(sk_le__feijiang.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and not player:isKongcheng() and
    player:usedSkillTimes(sk_le__feijiang.name, Player.HistoryTurn) == 0
  end,
})

sk_le__feijiang:addEffect(fk.TurnEnd, {
  name = "#sk_le__feijiang_delay",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("sk_le__feijiang") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("sk_le__feijiang"), Card.PlayerHand, player, fk.ReasonJustMove,
      "sk_le__feijiang", nil, false, player)
  end,
})
sk_le__feijiang:addEffect(fk.DamageCaused, {
  name = "#sk_le__feijiang_delay",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return data.to == player and player.room.logic:damageByCardEffect() and
    table.contains(data.card.skillNames, "sk_le__feijiang")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage * 2
  end,
})

sk_le__feijiang:addEffect("targetmod", {
  name = "#sk_le__feijiang_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and type(card) == "table" and table.contains(card.skillNames, "sk_le__feijiang")
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and type(card) == "table" and table.contains(card.skillNames, "sk_le__feijiang")
  end,
})

return sk_le__feijiang
